package com.tjy.farmer.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tjy.common.annotation.Log;
import com.tjy.common.core.controller.BaseController;
import com.tjy.common.core.domain.AjaxResult;
import com.tjy.common.enums.BusinessType;
import com.tjy.farmer.domain.FarmerAlarm;
import com.tjy.farmer.service.IFarmerAlarmService;
import com.tjy.common.utils.poi.ExcelUtil;
import com.tjy.common.core.page.TableDataInfo;

/**
 * 蜂农越界报警记录Controller
 *
 * @author tjy
 * @date 2025-09-16
 */
@RestController
@RequestMapping("/farmer/alarm")
public class FarmerAlarmController extends BaseController {
    @Autowired
    private IFarmerAlarmService farmerAlarmService;

    /**
     * 查询蜂农越界报警记录列表
     */
    @PreAuthorize("@ss.hasPermi('farmer:alarm:list')")
    @GetMapping("/list")
    public TableDataInfo list(FarmerAlarm farmerAlarm) {
        startPage();
        List<FarmerAlarm> list = farmerAlarmService.selectFarmerAlarmList(farmerAlarm);
        return getDataTable(list);
    }

    /**
     * 导出蜂农越界报警记录列表
     */
    @PreAuthorize("@ss.hasPermi('farmer:alarm:export')")
    @Log(title = "蜂农越界报警记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FarmerAlarm farmerAlarm) {
        List<FarmerAlarm> list = farmerAlarmService.selectFarmerAlarmList(farmerAlarm);
        ExcelUtil<FarmerAlarm> util = new ExcelUtil<FarmerAlarm>(FarmerAlarm.class);
        util.exportExcel(response, list, "蜂农越界报警记录数据");
    }

    /**
     * 获取蜂农越界报警记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('farmer:alarm:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(farmerAlarmService.selectFarmerAlarmById(id));
    }

    /**
     * 新增蜂农越界报警记录
     */
    @PreAuthorize("@ss.hasPermi('farmer:alarm:add')")
    @Log(title = "蜂农越界报警记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FarmerAlarm farmerAlarm) {
        return toAjax(farmerAlarmService.insertFarmerAlarm(farmerAlarm));
    }

    /**
     * 修改蜂农越界报警记录
     */
    @PreAuthorize("@ss.hasPermi('farmer:alarm:edit')")
    @Log(title = "蜂农越界报警记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FarmerAlarm farmerAlarm) {
        return toAjax(farmerAlarmService.updateFarmerAlarm(farmerAlarm));
    }

    /**
     * 删除蜂农越界报警记录
     */
    @PreAuthorize("@ss.hasPermi('farmer:alarm:remove')")
    @Log(title = "蜂农越界报警记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(farmerAlarmService.deleteFarmerAlarmByIds(ids));
    }
}
